<?php
// +----------------------------------------------------------------------+
// | The CompanyName 星座女神                                             |
// +----------------------------------------------------------------------+
// | Copyright (c) 2016, CompanyName 星座女神. All rights reserved.       |
// +----------------------------------------------------------------------+
// | Authors: CompanyName 星座女神.                                       |
// |                                                                      |
// +----------------------------------------------------------------------+
/**
 * 小程序 获取星座成分
 * @version  1.0
 * @author   guoqiang
 * @date     20200424
 */

namespace app\astro\controller;

use app\common\model\Recode;
use think\Controller;// 基础控制器
// 星盘记分类
class MiniAppSignscore extends Controller
{
    private $show_num = 12;// 星座成分显示星座数量 [包含其他]
    private $base_data = [];
    // 12星座默认得分为0
    private $signs_score = [1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0,];
    private $planets_in_sign = [];
    // 星座关键词
    private $sign_tags = [
        1 => ['简单', '急性子', '行动', '冲动', '直接', '讲义气', '鲁莽', '自我',],
        2 => ['固执', '稳定', '占有', '爱钱', '踏实', '抗拒改变', '美食家', '知觉敏锐',],
        3 => ['好奇心', '善变', '多才多艺', '语言天赋', '学得快', '一心二用', '适应',],
        4 => ['多愁善感', '掌控欲', '保护', '收藏', '安全感', '顽固', '记忆',],
        5 => ['慷慨', '忠诚', '表演', '虚荣', '展示', '鼓舞', '创造力',],
        6 => ['谦逊', '服务', '关注细节', '谨慎', '挑剔', '疑病症', '分析', '自我反省',],
        7 => ['妥协', '秩序', '优雅', '懒散', '社交', '回避冲突', '犹豫', '依赖',],
        8 => ['无畏', '不屈', '怀疑', '占有欲', '极端', '探秘', '保密',],
        9 => ['乐观', '冒险精神', '流浪者', '胆子大', '抓重点', '旅行', '理想主义', '说教',],
        10 => ['自我约束', '老成', '传统', '耐心', '勤勉', '保守', '组织规划', '成就感',],
        11 => ['客观理性', '友善', '坦诚', '抽离', '反传统', '独立', '我行我素', '科技',],
        12 => ['失去自我', '包容', '慈悲', '牺牲', '自怜', '幻想', '逃避现实',],
    ];

    private $planet_insign_tags = array(
        17 =>
            array(
                1 =>
                    array(
                        0 => '闲不住',
                        1 => '果断',
                        2 => '易厌倦',
                    ),
                2 =>
                    array(
                        0 => '耐心',
                        1 => '处惊不变',
                        2 => '追求品质',
                    ),
                3 =>
                    array(
                        0 => '健谈',
                        1 => '兴趣广泛',
                        2 => '急中生智',
                    ),
                4 =>
                    array(
                        0 => '同情心',
                        1 => '温柔',
                        2 => '情绪泛滥',
                    ),
                5 =>
                    array(
                        0 => '骄傲',
                        1 => '忠诚',
                        2 => '正直',
                    ),
                6 =>
                    array(
                        0 => '谦逊',
                        1 => '挑剔',
                        2 => '勤奋',
                    ),
                7 =>
                    array(
                        0 => '公平',
                        1 => '犹豫不决',
                        2 => '优柔寡断',
                    ),
                8 =>
                    array(
                        0 => '隐私',
                        1 => '深沉',
                        2 => '猜不透',
                    ),
                9 =>
                    array(
                        0 => '乐观',
                        1 => '不受羁绊',
                        2 => '探险家',
                    ),
                10 =>
                    array(
                        0 => '行事得体',
                        1 => '少年老成',
                        2 => '自我怀疑',
                    ),
                11 =>
                    array(
                        0 => '冷静',
                        1 => '博爱',
                        2 => '平等主义',
                    ),
                12 =>
                    array(
                        0 => '善解人意',
                        1 => '救世主',
                        2 => '艺术家',
                    ),
            ),
        0 =>
            array(
                1 =>
                    array(
                        0 => '冲动',
                        1 => '直接',
                        2 => '好斗',
                    ),
                2 =>
                    array(
                        0 => '固执',
                        1 => '踏实',
                        2 => '爱钱',
                    ),
                3 =>
                    array(
                        0 => '聪明',
                        1 => '善变',
                        2 => '适应性强',
                    ),
                4 =>
                    array(
                        0 => '顾家',
                        1 => '情绪化',
                        2 => '腼腆',
                    ),
                5 =>
                    array(
                        0 => '自信',
                        1 => '温暖',
                        2 => '宽宏大量',
                    ),
                6 =>
                    array(
                        0 => '低调',
                        1 => '完美主义',
                        2 => '细节控',
                    ),
                7 =>
                    array(
                        0 => '礼貌',
                        1 => '优雅',
                        2 => '外貌协会',
                    ),
                8 =>
                    array(
                        0 => '占有欲',
                        1 => '神秘',
                        2 => '临危不乱',
                    ),
                9 =>
                    array(
                        0 => '自由',
                        1 => '粗心大意',
                        2 => '精力充沛',
                    ),
                10 =>
                    array(
                        0 => '稳重',
                        1 => '正经八百',
                        2 => '谨慎',
                    ),
                11 =>
                    array(
                        0 => '表里如一',
                        1 => '独立',
                        2 => '与众不同',
                    ),
                12 =>
                    array(
                        0 => '难以捉摸',
                        1 => '迷糊',
                        2 => '爱做梦',
                    ),
            ),
        1 =>
            array(
                1 =>
                    array(
                        0 => '急性子',
                        1 => '内心透明',
                        2 => '率真',
                    ),
                2 =>
                    array(
                        0 => '稳定',
                        1 => '内心强大',
                        2 => '慢性子',
                    ),
                3 =>
                    array(
                        0 => '心眼多',
                        1 => '好学',
                        2 => '变得快',
                    ),
                4 =>
                    array(
                        0 => '多愁善感',
                        1 => '念旧',
                        2 => '保护欲强',
                    ),
                5 =>
                    array(
                        0 => '慷慨',
                        1 => '浮夸',
                        2 => '热情',
                    ),
                6 =>
                    array(
                        0 => '爱管闲事',
                        1 => '助人为乐',
                        2 => '实事求是',
                    ),
                7 =>
                    array(
                        0 => '陪伴',
                        1 => '伪善',
                        2 => '和谐',
                    ),
                8 =>
                    array(
                        0 => '多疑',
                        1 => '猜忌',
                        2 => '精于算计',
                    ),
                9 =>
                    array(
                        0 => '理想主义',
                        1 => '无拘无束',
                        2 => '率直',
                    ),
                10 =>
                    array(
                        0 => '压抑',
                        1 => '工作狂',
                        2 => '考虑周全',
                    ),
                11 =>
                    array(
                        0 => '古怪',
                        1 => '诚实',
                        2 => '直截了当',
                    ),
                12 =>
                    array(
                        0 => '慈悲',
                        1 => '敏感',
                        2 => '有爱心',
                    ),
            ),
        3 =>
            array(
                1 =>
                    array(
                        0 => '简单爱',
                        1 => '热情',
                        2 => '有魅力',
                    ),
                2 =>
                    array(
                        0 => '美食家',
                        1 => '爱享受',
                        2 => '要拥抱',
                    ),
                3 =>
                    array(
                        0 => '花言巧语',
                        1 => '劈腿',
                        2 => '薄情',
                    ),
                4 =>
                    array(
                        0 => '善解人意',
                        1 => '体贴',
                        2 => '敏感',
                    ),
                5 =>
                    array(
                        0 => '秀恩爱',
                        1 => '自大',
                        2 => '好面子',
                    ),
                6 =>
                    array(
                        0 => '自卑',
                        1 => '严苛',
                        2 => '守规矩',
                    ),
                7 =>
                    array(
                        0 => '甜蜜',
                        1 => '友善',
                        2 => '彬彬有礼',
                    ),
                8 =>
                    array(
                        0 => '深情',
                        1 => '灵肉合一',
                        2 => '性感',
                    ),
                9 =>
                    array(
                        0 => '寻欢作乐',
                        1 => '没心没肺',
                        2 => '风趣',
                    ),
                10 =>
                    array(
                        0 => '冷幽默',
                        1 => '可靠',
                        2 => '保守',
                    ),
                11 =>
                    array(
                        0 => '开明',
                        1 => '反叛',
                        2 => '随心所欲',
                    ),
                12 =>
                    array(
                        0 => '暧昧',
                        1 => '浪漫',
                        2 => '无私奉献',
                    ),
            ),
        2 =>
            array(
                1 =>
                    array(
                        0 => '嘴巴快',
                        1 => '好争辩',
                        2 => '语言攻击',
                    ),
                2 =>
                    array(
                        0 => '嗓子好',
                        1 => '知觉敏锐',
                        2 => '慢悠悠',
                    ),
                3 =>
                    array(
                        0 => '伶牙俐齿',
                        1 => '一心二用',
                        2 => '发散思维',
                    ),
                4 =>
                    array(
                        0 => '记性好',
                        1 => '旁敲侧击',
                        2 => '顽固',
                    ),
                5 =>
                    array(
                        0 => '夸夸其谈',
                        1 => '感染力',
                        2 => '演说家',
                    ),
                6 =>
                    array(
                        0 => '分析',
                        1 => '质疑',
                        2 => '细心',
                    ),
                7 =>
                    array(
                        0 => '同理心',
                        1 => '换位思考',
                        2 => '社交达人',
                    ),
                8 =>
                    array(
                        0 => '一针见血',
                        1 => '言简意赅',
                        2 => '全神贯注',
                    ),
                9 =>
                    array(
                        0 => '心胸开阔',
                        1 => '志向远大',
                        2 => '开放',
                    ),
                10 =>
                    array(
                        0 => '谨言慎行',
                        1 => '观念保守',
                        2 => '一板一眼',
                    ),
                11 =>
                    array(
                        0 => '语出惊人',
                        1 => '就事论事',
                        2 => '求真相',
                    ),
                12 =>
                    array(
                        0 => '路痴',
                        1 => '文艺爱好者',
                        2 => '没主见',
                    ),
            ),
        4 =>
            array(
                1 =>
                    array(
                        0 => '暴脾气',
                        1 => '明刀明枪',
                        2 => '立即行动',
                    ),
                2 =>
                    array(
                        0 => '抗拒改变',
                        1 => '闷脾气',
                        2 => '倔强',
                    ),
                3 =>
                    array(
                        0 => '好争辩',
                        1 => '打情骂俏',
                        2 => '社交广',
                    ),
                4 =>
                    array(
                        0 => '通情达理',
                        1 => '生闷气',
                        2 => '绕圈子',
                    ),
                5 =>
                    array(
                        0 => '虚张声势',
                        1 => '爱出风头',
                        2 => '引人注目',
                    ),
                6 =>
                    array(
                        0 => '唠叨',
                        1 => '吹毛求疵',
                        2 => '肯帮忙',
                    ),
                7 =>
                    array(
                        0 => '好争论',
                        1 => '摇摆不定',
                        2 => '合作',
                    ),
                8 =>
                    array(
                        0 => '魅力四射',
                        1 => '善妒',
                        2 => '谋略家',
                    ),
                9 =>
                    array(
                        0 => '不安于室',
                        1 => '冒险',
                        2 => '直接',
                    ),
                10 =>
                    array(
                        0 => '认真',
                        1 => '野心勃勃',
                        2 => '自律',
                    ),
                11 =>
                    array(
                        0 => '离经叛道',
                        1 => '睿智',
                        2 => '个人主义',
                    ),
                12 =>
                    array(
                        0 => '逃避现实',
                        1 => '多情',
                        2 => '随波逐流',
                    ),
            ),
    );

    public function __construct($data = [])
    {
        if (empty($data)) return ['status' => '30001', 'Invalid Data!'];

        $this->base_data = $data;
    }

    public function _initload($rid)
    {
        $this->planet_in_sign();
        $this->asc_planet_and_mc_planet_in_sign();
        $this->planet_in_sign_structure_top();
        $this->planet_phase_in_sign();
        $this->asc_and_mc_phase_in_sign();
//        $this->get_planet_active();// 行星转化的星座能量去掉
//        p($this->get_percentage());
        $data = $this->get_percentage();
//        p($data);exit;
        $temp = [];
        foreach ($data as $k => $d)
        {
            $sign_id = $d['id'];
//            p($this->planets_in_sign[$sign_id]);
            if (isset($this->planets_in_sign[$sign_id]))
            {
                $in_sign = $this->planets_in_sign[$sign_id];
                foreach ($in_sign as $pid)
                {
                    $d['in_sign'][] = [
                        'id' => $pid,
                        // 'status' => $this->getStatusForSigntext($rid, $sign_id, $pid)
                    ];
                }
                $temp[] = $d;
            }
//            $data[$k]['in_sign'] = isset($this->planets_in_sign[$sign_id]) ? $this->planets_in_sign[$sign_id] : [];
        }

        return $temp;
    }

    /**
     * 获取当前档案行星落座词条是否已判断完准确不准确
     * @param int $rid
     * @param $sign
     * @param $planet
     * @return bool
     * @throws \think\Exception
     */
    protected function getStatusForSigntext($rid, $sign, $planet)
    {
        //获取已打分的行星落座词条数量
        $yes = db()->table('app_sign_text')
            ->alias('t')
            ->field('y.yes,y.userid rid')
            ->join('app_sign_yesno y', 't.id=y.sign_id', 'LEFT')
            ->join('app_recode r', 'y.userid=r.id', 'LEFT')
            ->where("(r.type=t.sex or t.sex=99) AND t.planet_id=$planet AND t.sign_id=$sign AND r.id=$rid")
            ->count();

        $recode = (new Recode())->getRecode(['id' => $rid]);

//        $recode = db()->table('app_recode')->where('id',$rid)->find();
        //获取行星落座词条总量
        try
        {
            $yes_count = db()->table('app_sign_text')
                ->where("(sex={$recode['type']} or sex=99) AND planet_id=$planet AND sign_id=$sign")
                ->count();
        }
        catch (\Exception $e)
        {
            $yes_count = db()->table('app_sign_text')
                ->where("(sex={$recode['type']} or sex=99) AND planet_id=$planet AND sign_id=$sign")
                ->fetchSql()
                ->count();

            \think\Log::write('错误的sql：' . $yes_count, 'app_sign_text_sql_error', true);

            $yes_count = 0;
        }

//        p($yes);
//        p($recode);
//        p($yes_count);
//        exit;
//        if($sign == 6 && $planet == ASC)
//        {
//            echo "planet:$planet-sign:$sign-rid:$rid";
//            p($yes);
//            exit;
//        }
//        echo "planet:$planet-sign:$sign-rid:$rid";
//        p($yes);
//        exit;
//        if(empty($yes)) return false;

//        foreach($yes as $t) if(!$t['rid'] || ($rid == $t['rid'] && $t['yes'] !== 1 && $t['yes'] !== -1)) return false;
        if ($yes != $yes_count) return false;
        return true;
    }

    /**
     * 计算星座得分
     */
    public function cacl_sign()
    {
        $this->planet_in_sign();
        $this->asc_planet_and_mc_planet_in_sign();
        $this->planet_in_sign_structure_top();
        $this->planet_phase_in_sign();
        $this->asc_and_mc_phase_in_sign();
//        $this->get_planet_active();

//        return $this->get_percentage();
        p($this->get_percentage());
//        exit;
        p($this->signs_score);
    }

    /**
     * 获取百分比
     * @return array
     */
    public function get_percentage()
    {
        $base_planet = [0, 1, 2, 3, 4, ASC];
        $total_arr = [];
        foreach ($base_planet as $i)
        {
            $in_sign = $this->base_data['planets'][$i]['in_sign_id'];
//            p($in_sign);
            $total_arr[$in_sign] = $this->signs_score[$in_sign];
        }
//        p($total_arr);
//        $total  = $total_arr;
//        p($this->signs_score);
//        rsort($total_arr);
//        p($total_arr);
//        exit;
        $total = array_sum($total_arr);


        $percentage = [];
//        p($this->signs_score);
        foreach ($total_arr as $k => $s)
        {
            if ($k % 4 == 1) $type = '火';
            elseif ($k % 4 == 2) $type = '土';
            elseif ($k % 4 == 3) $type = '风';
            elseif ($k % 4 == 0) $type = '水';

            $percentage[] = [
                'id' => $k,
                'type' => $type,
                'value' => $s,
                'percent' => $s / $total,
                'tags' => $this->get_sign_tags($k),
            ];
        }
//        p($percentage);
        // 按百分比排序 - 倒叙
        for ($i = 0; $i < count($percentage); $i++)
        {
            for ($j = $i + 1; $j < count($percentage); $j++)
            {
                if ($percentage[$i]['value'] < $percentage[$j]['value'])
                {
                    $temp = $percentage[$i];
                    $percentage[$i] = $percentage[$j];
                    $percentage[$j] = $temp;
                }
            }
        }
//        $total_new = 0;
//        for($l=1;$l<=$this->show_num;$l++)
//        {
//            $total_new += $percentage[$l]['value'];
//            $ret[] = $percentage[$l];
//        }
//        $score_other = $total - $total_new;

//        $ret[$this->show_num - 1] = [
//            'id'=>'',
//            'name_glyph'=>'',
//            'name_en'=>'other',
//            'name_cn'=>'',
//            'name'=>'其他',
//            'value'=>$score_other,
//            'percent'=>$score_other / $total,
//            'percent_cn'=>round($score_other / $total * 100,2) . '%',
//        ];
//        p($ret);
        return $percentage;
    }

    protected function get_sign_tags($id = null)
    {
        if (!$id) return [];
        $array_rand = array_rand($this->sign_tags[$id], 3);
        return [
            $this->sign_tags[$id][$array_rand[0]],
            $this->sign_tags[$id][$array_rand[1]],
            $this->sign_tags[$id][$array_rand[2]],
        ];
    }

    /**
     * 1、行星落座记分
     * 日月：该星座+100  150
     * 金水火：该星座+50
     * 木土：该星座+25
     * 上升点：该星座+70  120
     * //     * 中天：该星座+30   50
     * 北交：+10
     * 天海冥：+5
     */
    protected function planet_in_sign()
    {
        foreach ($this->base_data['planets'] as $i => $p)
        {
            if (in_array($i, [0, 1, 2, 3, 4, ASC])) $this->planets_in_sign[$this->base_data['planets'][$i]['in_sign_id']][] = $i;
            // 日月 +150
            if ($i == 0 || $i == 1)
            {
                $this->signs_score[$this->base_data['planets'][$i]['in_sign_id']] += 150;
            } // 水金火 +70
            elseif ($i == 2 || $i == 3 || $i == 4)
            {
                $this->signs_score[$this->base_data['planets'][$i]['in_sign_id']] += 70;
            } // 木土 +25
            elseif ($i == 5 || $i == 6)
            {
                $this->signs_score[$this->base_data['planets'][$i]['in_sign_id']] += 25;
            } // 天海冥 +5
            elseif ($i == 7 || $i == 8 || $i == 9)
            {
                $this->signs_score[$this->base_data['planets'][$i]['in_sign_id']] += 5;
            } // 北交点 +10
            elseif ($i == 12)
            {
                $this->signs_score[$this->base_data['planets'][$i]['in_sign_id']] += 10;
            } // 上升点 +120
            elseif ($i == ASC)
            {
                $this->signs_score[$this->base_data['planets'][$i]['in_sign_id']] += 120;
            }
//            // 中天 +50
//            elseif($i == MC)
//            {
//                $this->signs_score[$this->base_data['planets'][$i]['in_sign_id']] += 50;
//            }
        }
    }

    /**
     * 2、检视命主星和中天主星所在星座
     * 命主星：所在星座+40
     * 中天主星：所在星座+20
     */
    protected function asc_planet_and_mc_planet_in_sign()
    {
        // 命主星：所在星座+40
        if ($this->base_data['houses'][1]['protect_id'] == $this->base_data['houses'][1]['protect_ancient_id'])
        {
            $this->signs_score[$this->base_data['houses'][1]['protect_insign_id']] += 40;
        } else
        {
            $this->signs_score[$this->base_data['houses'][1]['protect_insign_id']] += 40;
            $this->signs_score[$this->base_data['houses'][1]['protect_ancient_insign_id']] += 40;
        }
        // 中天主星：所在星座+20
        if ($this->base_data['houses'][10]['protect_id'] == $this->base_data['houses'][10]['protect_ancient_id'])
        {
            $this->signs_score[$this->base_data['houses'][10]['protect_insign_id']] += 20;
        } else
        {
            $this->signs_score[$this->base_data['houses'][10]['protect_insign_id']] += 20;
            $this->signs_score[$this->base_data['houses'][10]['protect_ancient_insign_id']] += 20;
        }

    }

    /**
     * 3、检视X星座中的星体所参与的结构
     * 若有某星为T三角顶点，X星座+30（若有两颗或以上星体合相在X星座，且同为T三角顶点，则不重复计分；若有两颗或以上星体都在X星座，但不合相，同为T三角顶点，则可重复计分，以下各项相同） t_square
     * 若有某星为小三角顶点，X星座+10    small_triangle
     * 若有某星为风筝顶点，X星座+20 kite
     */
    protected function planet_in_sign_structure_top()
    {
        if (!empty($this->base_data['structure']['t_square']))
        {
            $t_square = [];
            foreach ($this->base_data['structure']['t_square'] as $i => $t)
            {
                // 不相同顶点T三角 顶点所在星座+30
                if (empty($t_square) || !in_array($t[2]['id'], $t_square))
                {
                    $this->signs_score[$t[2]['in_sign_id']] += 30;
                    $t_square[] = $t[2]['id'];
                }
                if (count($t_square) > 0)
                {
                    foreach ($t_square as $it)
                    {
                        // 顶点相同时，则算为一个T三角
                        if ($it != $t[2]['id'] &&
                            !($t[2]['in_sign_id'] == $this->base_data['planets'][$it]['in_sign_id']
                                && (isset($this->base_data['planets'][$t[2]['id']]['phase'][$t[2]['id'] . '-' . $it])
                                    || isset($this->base_data['planets'][$t[2]['id']]['phase'][$it . '-' . $t[2]['id']])))
                        )
                        {
                            $this->signs_score[$t[2]['in_sign_id']] += 30;
                            $t_square[] = $t[2]['id'];
                        }
                    }
                }
            }
        }
        if (!empty($this->base_data['structure']['small_triangle']))
        {
            $small_triangle = [];
            foreach ($this->base_data['structure']['small_triangle'] as $i => $st)
            {
                // 不相同顶点小三角 顶点所在星座+30
                if (empty($small_triangle) || !in_array($st[2]['id'], $small_triangle))
                {

                    $this->signs_score[$st[2]['in_sign_id']] += 10;
                    $small_triangle[] = $st[2]['id'];
                }
                if (count($small_triangle) > 0)
                {
                    foreach ($small_triangle as $it)
                    {
                        // 顶点相同时，则算为一个小三角
                        if ($it != $st[2]['id'] &&
                            !($st[2]['in_sign_id'] == $this->base_data['planets'][$it]['in_sign_id']
                                && (isset($this->base_data['planets'][$st[2]['id']]['phase'][$st[2]['id'] . '-' . $it])
                                    || isset($this->base_data['planets'][$st[2]['id']]['phase'][$it . '-' . $st[2]['id']])))
                        )
                        {
                            $this->signs_score[$st[2]['in_sign_id']] += 10;
                            $small_triangle[] = $st[2]['id'];
                        }
                    }
                }
            }
        }
        if (!empty($this->base_data['structure']['kite']))
        {
            $kite = [];
            foreach ($this->base_data['structure']['kite'] as $i => $st)
            {
                // 不相同顶点大风筝 顶点所在星座+30
                if (empty($kite) || !in_array($st[3]['id'], $kite))
                {
                    $this->signs_score[$st[3]['in_sign_id']] += 20;
                    $kite[] = $st[3]['id'];
                }
                if (count($kite) > 0)
                {
                    foreach ($kite as $it)
                    {
                        // 顶点相同时，则算为一个大风筝
                        if ($it != $st[3]['id'] &&
                            !($st[3]['in_sign_id'] == $this->base_data['planets'][$it]['in_sign_id']
                                && (isset($this->base_data['planets'][$st[3]['id']]['phase'][$st[3]['id'] . '-' . $it])
                                    || isset($this->base_data['planets'][$st[3]['id']]['phase'][$it . '-' . $st[3]['id']])))
                        )
                        {
                            $this->signs_score[$st[3]['in_sign_id']] += 20;
                            $kite[] = $st[3]['id'];
                        }
                    }
                }
            }
        }
    }

    /**
     * 4、依次检视星盘上与日月水金火有关的每一个相位
     * A 计算相位关联指数
     * B 每个相位中，与日月水金火成相的另一方，所在星座得分+对方的基础值*关联指数（若相位双方都是个人星，则计算两次）
     */
    protected function planet_phase_in_sign()
    {
        // 日月水金火
        for ($i = 0; $i < 5; $i++)
        {
            $base_score = $i < 2 ? 150 : 50;
            $planet = $this->base_data['planets'][$i];
            $this->associated_index($planet, $base_score);
        }
    }

    /**
     * 5、检视与Asc、Mc有关的每一个相位
     * A 计算相位关联指数
     * B 每个相位中，与Asc/Mc成相的星体，所在星座得分+Asc/Mc的基础值*关联指数
     */
    protected function asc_and_mc_phase_in_sign()
    {
        // 检测与ASC有关的相位
        $planet = $this->base_data['planets'][ASC];
        $this->associated_index($planet, 120);

        // 检测与MC有关的相位
        $planet = $this->base_data['planets'][MC];
        $this->associated_index($planet, 50);
    }

    /**
     * 计算关联指数
     * 1、    判定相位类型，求得相位影响系数w：合相1，对分、四分、三分0.8，六分0.7
     * 2、    若是该星唯一相位，或唯一7度以内相位，则w=w+0.2
     * 3、    若该相位1度以内，w=w+0.2；若是1度以外3度以内，w=w+0.1；7度以外相位且非唯一，w=w-0.1
     * 4、    检测相位中是否存在接纳，
     *          若存在单向本垣接纳，w=w+0.4，若存在单向擢升接纳，w=w+0.3，
     *          若存在双向本垣接纳（即互容）w=w+0.8，若存在本垣-擢升接纳，w=w+0.7，
     *          若存在擢升-擢升接纳，w=w+0.6,（三王星也计算在内，如水瓶座土星、天王都是本垣）
     * 5、    检测其它与其不成相位的星体，是否与其形成无相位互容。若存在无相位互容，则与其所互容星座关联指数=0.6
     * 6、    与对应星座的关联指数=w*0.2
     */
    protected function associated_index($planet = [], $base_score = 0)
    {
        $count_orb_7 = 0;// 7度以内相位数量
        $w = [];
        if (!empty($planet['phase']))
        {
            foreach ($planet['phase'] as $i => $asp)
            {
                $id = explode("-", $i);
                if ($id[1] > 9) continue;
                $w[$i] = 0;// 关联指数
                // 判定相位类型，求得相位影响系数w：合相1，对分、四分、三分0.8，六分0.7
                if ($asp['phase_e'] == 0) $w[$i] = 1;
                elseif ($asp['phase_e'] == 180 || $asp['phase_e'] == 90 || $asp['phase_e'] == 120) $w[$i] = 0.8;
                elseif ($asp['phase_e'] == 60) $w[$i] = 0.7;
                if ($asp['phase_orb'] < 7) $count_orb_7++;
            }
        }

        // 若是该星唯一相位，或唯一7度以内相位，则w=w+0.2
        if ((is_countable($planet['phase']) && count($planet['phase']) == 1) || $count_orb_7 == 1)
        {
            if (!isset($w[array_keys($planet['phase'])[0]])) $w[array_keys($planet['phase'])[0]] = 0;
            $w[array_keys($planet['phase'])[0]] += 0.2;
        }

        if (!empty($planet['phase']))
        {
            foreach ($planet['phase'] as $i => $asp)
            {
                $id = explode("-", $i);
                if ($id[1] > 9) continue;
                // 若该相位1度以内，w=w+0.2
                if ($asp['phase_orb'] < 1) $w[$i] += 0.2;
                // 若是1度以外3度以内，w=w+0.1
                elseif ($asp['phase_orb'] < 3 && $asp['phase_orb'] >= 1) $w[$i] += 0.1;
                // 7度以外相位且非唯一，w=w-0.1
                elseif ($asp['phase_orb'] > 7 && count($planet['phase']) > 1) $w[$i] -= 0.1;
            }
        }
        // 获取所有互容接纳关系包含天海冥
        $characteristic = $this->recept_or_mutual_recept();
        #检测相位中是否存在接纳，
        #若存在单向本垣接纳，w=w+0.4，
        #若存在单向擢升接纳，w=w+0.3，
        #若存在双向本垣接纳（即互容）w=w+0.8，
        #若存在本垣-擢升接纳（即互容），w=w+0.7，
        #若存在擢升-擢升接纳（即互容），w=w+0.6,（三王星也计算在内，如水瓶座土星、天王都是本垣）
        foreach ($characteristic as $k => $chara)
        {
            // 单向接纳
            if ($chara['status'] == 1 && ($chara['id1'] == $planet['id'] || $chara['id2'] == $planet['id']))
            {
                // 单向本垣接纳
                if ($chara['relation_by']['walls'] == 1) $w[$chara['id1'] . '-' . $chara['id2']] += 0.4;
                // 单向擢升接纳
                elseif ($chara['relation_by']['promote'] == 1) $w[$chara['id1'] . '-' . $chara['id2']] += 0.3;

            } // 互溶
            elseif ($chara['status'] == 2 && ($chara['id1'] == $planet['id'] || $chara['id2'] == $planet['id']))
            {
                // 是否为无相位互容
                // 无相位互容。若存在无相位互容，则与其所互容星座关联指数=0.6
                if (!$chara['phase'])
                {
                    if (isset($w[$chara['id1'] . '-' . $chara['id2']])) $w[$chara['id1'] . '-' . $chara['id2']] = 0.6;
                    if (isset($w[$chara['id2'] . '-' . $chara['id1']])) $w[$chara['id2'] . '-' . $chara['id1']] = 0.6;

                } // 本垣-本垣
                elseif ($chara['relation_by']['walls1'] == 1 && $chara['relation_by']['walls2'] == 1)
                {
                    $w[$chara['id1'] . '-' . $chara['id2']] += 0.8;
                } // 本垣-擢升
                elseif ($chara['relation_by']['walls1'] == 1 && $chara['relation_by']['promote2'] == 1
                    || $chara['relation_by']['promote1'] == 1 && $chara['relation_by']['walls2'] == 1)
                {

                    $w[$chara['id1'] . '-' . $chara['id2']] += 0.7;
                } // 擢升-擢升
                elseif ($chara['relation_by']['promote1'] == 1 && $chara['relation_by']['promote2'] == 1)
                {
                    $w[$chara['id1'] . '-' . $chara['id2']] += 0.6;
                }
            }
        }
        // 与对应星座的关联指数=w*0.2
        foreach ($w as $k => $ww)
        {
            $key = explode('-', $k);
            $change = 0.2;
            // 日月 +150
            if ($key[1] == 0 || $key[1] == 1)
            {
                $change *= 150 * $ww;
            } // 水金火 +50
            elseif ($key[1] == 2 || $key[1] == 3 || $key[1] == 4)
            {
                $change *= 50 * $ww;
            } // 木土 +25
            elseif ($key[1] == 5 || $key[1] == 6)
            {
                $change *= 25 * $ww;
            } // 天海冥 +5
            elseif ($key[1] == 7 || $key[1] == 8 || $key[1] == 9)
            {
                $change *= 5 * $ww;
            } // 北交点 +10
            elseif ($key[1] == 12)
            {
                $change *= 10 * $ww;
            } // 上升点 +70
            elseif ($key[1] == ASC)
            {
                $change *= 120 * $ww;
            } // 中天 +30
            elseif ($key[1] == MC)
            {
                $change *= 50 * $ww;
            }
            $this->signs_score[$this->base_data['planets'][$key[0]]['in_sign_id']] += $change;
        }
    }

    /**
     * 计算天海冥互容接纳关系
     * 日月水金火木土天海冥
     */
    protected function recept_or_mutual_recept()
    {
        $ret = [];
        $miscible = [];// 互溶
        // 日月水金火木土天海冥
        for ($i = 0; $i <= 8; $i++)
        {
            for ($l = 0; $l <= 9; $l++)
            {
                $i_ancient = $this->planet_in_ancient($i, $this->base_data['planets'][$l]['in_sign_id'],
                    $this->base_data['planets'][$l]['in_sign_deg_e']);
                $l_ancient = $this->planet_in_ancient($l, $this->base_data['planets'][$i]['in_sign_id'],
                    $this->base_data['planets'][$i]['in_sign_deg_e']);

                // 互容
                if ($i_ancient['power'] > 3 && $l_ancient['power'] > 3 && $i < $l)
                {
                    $ancient1 = '';
                    if ($i_ancient['walls'] == 1) $ancient1 .= '+本垣';
                    if ($i_ancient['promote'] == 1) $ancient1 .= '+擢升';
                    if ($i_ancient['trisection'] == 1) $ancient1 .= '+三分';
                    if ($i_ancient['extent'] == 1) $ancient1 .= '+界主';
                    if ($i_ancient['period'] == 1) $ancient1 .= '+十度';
                    $ancient1 = mb_substr($ancient1, 1);
                    $ancient2 = '';
                    if ($l_ancient['walls'] == 1) $ancient2 .= '+本垣';
                    if ($l_ancient['promote'] == 1) $ancient2 .= '+擢升';
                    if ($l_ancient['trisection'] == 1) $ancient2 .= '+三分';
                    if ($l_ancient['extent'] == 1) $ancient2 .= '+界主';
                    if ($l_ancient['period'] == 1) $ancient2 .= '+十度';
                    $ancient2 = mb_substr($ancient2, 1);
                    if (isset($planets[$i]['phase'][$i . '-' . $l]) || isset($planets[$i]['phase'][$l . '-' . $i]))
                        $have_phase = true;
                    else
                        $have_phase = false;
                    $miscible[] = $i . '-' . $l;
                    $miscible[] = $l . '-' . $i;
                    $ret[] = [
                        'id1' => $i,
                        'ancient1' => $ancient2,
                        'id2' => $l,
                        'ancient2' => $ancient1,
                        'phase' => $have_phase,// 是否成相位
                        'relation_by' => [
                            'walls1' => $i_ancient['walls'],
                            'promote1' => $i_ancient['promote'],
                            'trisection1' => $i_ancient['trisection'],
                            'extent1' => $i_ancient['extent'],
                            'period1' => $i_ancient['period'],
                            'walls2' => $l_ancient['walls'],
                            'promote2' => $l_ancient['promote'],
                            'trisection2' => $l_ancient['trisection'],
                            'extent2' => $l_ancient['extent'],
                            'period2' => $l_ancient['period'],
                        ],
                        'relation' => '互容',
                        'status' => 2,
                    ];
                } elseif (isset($planets[$i]['phase'][$i . '-' . $l]) && $l_ancient['power'] > 3)
                {
                    // 没有互溶
                    if (!in_array($i . '-' . $l, $miscible))
                    {
                        // 存在相位  接纳
                        $ancient2 = '';
                        $ancient1 = '';
                        if ($l_ancient['walls'] == 1) $ancient2 .= '+本垣';
                        if ($l_ancient['promote'] == 1) $ancient2 .= '+擢升';
                        if ($l_ancient['trisection'] == 1) $ancient2 .= '+三分';
                        if ($l_ancient['extent'] == 1) $ancient2 .= '+界主';
                        if ($l_ancient['period'] == 1) $ancient2 .= '+十度';
                        $ancient2 = mb_substr($ancient2, 1);
                        $ret[] = [
                            'id1' => $i,
                            'ancient1' => '',
                            'id2' => $l,
                            'ancient2' => $ancient2,
                            'relation_by' => [
                                'walls' => $l_ancient['walls'], 'promote' => $l_ancient['promote'], 'trisection' => $l_ancient['trisection'],
                                'extent' => $l_ancient['extent'], 'period' => $l_ancient['period']
                            ],
                            'relation' => '接纳',
                            'status' => 1,
                        ];
                    }

                }
            }
        }
        return $ret;
    }

    /**
     * 计算行星  1入庙 或 2失势
     * @param null $p_id 行星ID
     * @param null $p_insign_id 行星落座id
     * @param string $p_insign_deg 行星落座度数
     * @return bool
     */
    private function planet_in_ancient($p_id = null, $p_insign_id = null, $p_insign_deg = 0)
    {
        // 非古典七星落座位置也有该位置庙旺弱陷界十度信息
        if ($p_id === null || $p_id < 0 || $p_insign_id === null) return [];
        $ret = [
            'power' => 0,
            'walls' => false, 'walls_cn' => '',// 庙
            'promote' => false, 'promote_cn' => '',// 旺
            'trisection' => false, 'trisection_cn' => '',// 三分
            'extent' => false, 'extent_cn' => '',// 界
            'period' => false, 'period_cn' => '',// 面
            'migration' => false, 'migration_cn' => '',// 游走
            'or_walls_planet_id' => null, 'or_promote_planet_id' => null,
            'or_extent_planet_id' => null, 'or_period_planet_id' => null,
            'or_trisection_planet_id' => [],
        ];

        $fall = ($p_insign_id <= 6) ? ($p_insign_id + 6) : ($p_insign_id - 6);
        // 入庙
        if (config('astrolog.ancient')[$p_insign_id][0] == $p_id)
        {
            $ret['power'] += 5;
            $ret['walls'] = 1;
            $ret['walls_cn'] = '入庙';
        } elseif (config('astrolog.ancient')[$fall][0] == $p_id)
        {
            $ret['power'] -= 5;
            $ret['walls'] = 2;
            $ret['walls_cn'] = '失势';
        }

        $ret['or_walls_planet_id'] = config('astrolog.ancient')[$p_insign_id][0];
        $ret['or_walls_fall_planet_id'] = config('astrolog.ancient')[$fall][0];
        // 天王星  入庙 失势
        if ($p_id == 7)
        {
            if ($p_insign_id == 11)
            {
                $ret['power'] += 5;
                $ret['walls'] = 1;
                $ret['walls_cn'] = '入庙';
            } elseif ($p_insign_id == 5)
            {
                $ret['power'] -= 5;
                $ret['walls'] = 2;
                $ret['walls_cn'] = '失势';
            }
            $ret['or_walls_planet_id'] = 11;
            $ret['or_walls_fall_planet_id'] = 5;
        } // 海王星  入庙 失势
        elseif ($p_id == 8)
        {
            if ($p_insign_id == 12)
            {
                $ret['power'] += 5;
                $ret['walls'] = 1;
                $ret['walls_cn'] = '入庙';
            } elseif ($p_insign_id == 6)
            {
                $ret['power'] -= 5;
                $ret['walls'] = 2;
                $ret['walls_cn'] = '失势';
            }
            $ret['or_walls_planet_id'] = 12;
            $ret['or_walls_fall_planet_id'] = 6;
        } // 冥王星  入庙 失势
        elseif ($p_id == 9)
        {
            if ($p_insign_id == 8)
            {
                $ret['power'] += 5;
                $ret['walls'] = 1;
                $ret['walls_cn'] = '入庙';
            } elseif ($p_insign_id == 2)
            {
                $ret['power'] -= 5;
                $ret['walls'] = 2;
                $ret['walls_cn'] = '失势';
            }
            $ret['or_walls_planet_id'] = 8;
            $ret['or_walls_fall_planet_id'] = 2;
        }
        // 擢升
        if (config('astrolog.ancient')[$p_insign_id][1] !== '' && config('astrolog.ancient')[$p_insign_id][1] == $p_id)
        {
            $ret['power'] += 4;
            $ret['promote'] = 1;
            $ret['promote_cn'] = '擢升';
        } elseif (config('astrolog.ancient')[$fall][1] !== '' && config('astrolog.ancient')[$fall][1] == $p_id)
        {
            $ret['power'] -= 4;
            $ret['promote'] = 2;
            $ret['promote_cn'] = '落陷';
        }
        $ret['or_promote_planet_id'] = config('astrolog.ancient')[$p_insign_id][1];
        $ret['or_promote_fall_planet_id'] = config('astrolog.ancient')[$fall][1];
        // 三分
        if (in_array($p_id, config('astrolog.ancient')[$p_insign_id][2]))
        {
            $ret['power'] += 3;
            $ret['trisection'] = 1;
            $ret['trisection_cn'] = '三分';
        }
        $ret['or_trisection_planet_id'] = config('astrolog.ancient')[$p_insign_id][2];
        // 界主 界主为1 +2
//        if (session('xzns.extent') == 'ptolemy_world')
//            $extent = config('astrolog.ancient')[$p_insign_id][3]['ptolemy_world'];
//        else
        $extent = config('astrolog.ancient')[$p_insign_id][3]['default'];

        for ($i = 0; $i < 5; $i++)
        {
            if ($p_insign_deg > $extent[1][$i] && $p_insign_deg < $extent[1][$i + 1])
            {
                if ($extent[0][$i] == $p_id)
                {
                    $ret['power'] += 2;
                    $ret['extent'] = 1;
                    $ret['extent_cn'] = '界主';
                }
                $ret['or_extent_planet_id'] = $extent[0][$i];
            }
        }
        // 旬主或十度
        for ($i = 0; $i < 3; $i++)
        {
            $min = $i * 10;
            $max = $min + 10;
            if ($p_insign_deg > $min && $p_insign_deg < $max)
            {
                if (config('astrolog.ancient')[$p_insign_id][4][$i] == $p_id)
                {
                    $ret['power'] += 1;
                    $ret['period'] = 1;
                    $ret['period_cn'] = '旬主';
                }
                $ret['or_period_planet_id'] = config('astrolog.ancient')[$p_insign_id][4][$i];
            }
        }

        if (!$ret['walls'] && !$ret['promote'] && !$ret['trisection'] && !$ret['extent'] && !$ret['period'] && $ret['power'] == 0 && $p_id < 7)
        {
            $ret['power'] = -5;
            $ret['migration'] = 1;
            $ret['migration_cn'] = '游走';
        }
        if ($p_id > 6 && $p_id < 9 && $ret['walls'] == false)
        {
            $ret['power'] = -5;
            $ret['migration'] = 1;
            $ret['migration_cn'] = '游走';
        }

        return $ret;
    }


    // 获取行星活跃值
    private function get_planet_active()
    {
        $url = "http://xzns.iamylee.com/index.php?xz/xz/get_p_v";
        if (!session('userdata_insert'))
        {
            $record = new Record();
            $userinfo = $record->getTheBestRecord();
        } else
        {
            $userinfo = session('userdata_insert');
        }
//        p($userinfo);
        $longitude = $userinfo['ew'] * ($userinfo['long_deg'] + ($userinfo['long_min'] / 60));
        $latitude = $userinfo['ns'] * ($userinfo['lat_deg'] + ($userinfo['lat_min'] / 60));
        $post_data = [
            "year" => $userinfo['year'], "month" => $userinfo['month'], "day" => $userinfo['day'],
            "hour" => $userinfo['hour'], "minute" => $userinfo['minute'],
            "longitude" => $longitude,
            "latitude" => $latitude,
        ];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
        $output = curl_exec($ch);
        curl_close($ch);
        $actives = @json_decode($output, true)['data']['huoy_v'];
        //        p($actives);
        // 获取所有互容接纳关系包含天海冥
        $characteristic = $this->recept_or_mutual_recept();


        for ($i = 0; $i < 10; $i++)
        {
            // 狮子座+太阳活跃值
            if ($i == 0)
            {
                $this->signs_score[5] += $actives[$i]['total'] * 1 * 0.5;
            } // 巨蟹座+月亮活跃值
            elseif ($i == 1)
            {
                $this->signs_score[4] += $actives[$i]['total'] * 1 * 0.5;
            }
            //若水星在
            // 	火象星座，双子座+水星活跃值的二分之一
            //	土象星座，处女座+水星活跃值
            // 	风象星座，双子座+水星活跃值
            // 	水象星座，处女座+水星活跃值的二分之一
            elseif ($i == 2)
            {
                // 若水星落处女座，或与处女座星体存在接纳互容，则处女座+水星活跃的二分之一；
                // 若水星落双子座，或与双子座星体存在接纳互容，则双子座+水星活跃的二分之一；
                $st = false;
                if ($st == false && $this->base_data['planets'][$i]['in_sign_id'] == 3)
                {
                    // 水星落双子
                    $this->signs_score[3] += $actives[$i]['total'] * 0.5;
                    $st = true;
                    continue;
                } elseif ($st == false && $this->base_data['planets'][$i]['in_sign_id'] == 6)
                {
                    // 水星落处女
                    $this->signs_score[6] += $actives[$i]['total'] * 0.5;
                    $st = true;
                    continue;
                }
                foreach ($characteristic as $k => $chara)
                {
                    // 存在互容接纳关系
                    if ($st == false && ($chara['status'] == 1 || $chara['status'] == 2))
                    {
                        $sign1 = $this->base_data['planets'][$chara['id1']]['in_sign_id'];
                        $sign2 = $this->base_data['planets'][$chara['id2']]['in_sign_id'];
                        if (($chara['id1'] == $i && $sign2 == 3) || ($chara['id2'] == $i && $sign1 == 3))
                        {
                            $this->signs_score[3] += $actives[$i]['total'] * 0.5;
                            $st = true;
                            continue;
                        } elseif (($chara['id1'] == $i && $sign2 == 6) || ($chara['id2'] == $i && $sign1 == 6))
                        {
                            $this->signs_score[6] += $actives[$i]['total'] * 0.5;
                            $st = true;
                            continue;
                        }
                    }
                }
                // 不满足以上两个条件，则观察升、日、月、金、火、是否落在双子座或处女座，落的话，该星座+水星活跃的四分之一
                if ($st == false)
                {
                    if ($this->base_data['planets'][0]['in_sign_id'] == 3)
                    {
                        $this->signs_score[3] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][1]['in_sign_id'] == 3)
                    {
                        $this->signs_score[3] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][3]['in_sign_id'] == 3)
                    {
                        $this->signs_score[3] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][4]['in_sign_id'] == 3)
                    {
                        $this->signs_score[3] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][ASC]['in_sign_id'] == 3)
                    {
                        $this->signs_score[3] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][0]['in_sign_id'] == 6)
                    {
                        $this->signs_score[6] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][1]['in_sign_id'] == 6)
                    {
                        $this->signs_score[6] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][3]['in_sign_id'] == 6)
                    {
                        $this->signs_score[6] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][4]['in_sign_id'] == 6)
                    {
                        $this->signs_score[6] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][ASC]['in_sign_id'] == 6)
                    {
                        $this->signs_score[6] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                }
                // 不满足以上条件，
                //     若水星在火象星座，双子座+水星活跃值的四分之一
                //     若水星在土象星座，处女座+水星活跃值的二分之一
                //     若水星在风象星座，双子座+水星活跃值的二分之一
                //     若水星在水象星座，处女座+水星活跃值的四分之一
                if ($st == false && $this->base_data['planets'][$i]['in_sign_id'] % 4 == 1)
                {
                    $this->signs_score[3] += $actives[$i]['total'] * 0.5 * 0.5;
                    $st = true;
                    continue;
                } elseif ($st == false && $this->base_data['planets'][$i]['in_sign_id'] % 4 == 2)
                {
                    $this->signs_score[6] += $actives[$i]['total'] * 1 * 0.5;
                    $st = true;
                    continue;
                } elseif ($st == false && $this->base_data['planets'][$i]['in_sign_id'] % 4 == 3)
                {
                    $this->signs_score[3] += $actives[$i]['total'] * 1 * 0.5;
                    $st = true;
                    continue;
                } elseif ($st == false && $this->base_data['planets'][$i]['in_sign_id'] % 4 == 4)
                {
                    $this->signs_score[6] += $actives[$i]['total'] * 0.5 * 0.5;
                    $st = true;
                    continue;
                }
            }
            //若金星在
            // 	火象星座，天秤座+二分之一
            // 	土象星座，金牛座+金值
            // 	风象星座，天秤座+金值
            //	水象星座，金牛座+二分之一
            elseif ($i == 3)
            {
                // 若金星落金牛座，或与金牛座星体存在接纳互容，则金牛座+金星活跃的二分之一；
                // 若金星落天秤座，或与天秤座星体存在接纳互容，则天秤座+金星活跃的二分之一；
                // 不满足以上两个条件，则观察升日月金火是否落在金牛座或天秤座，落的话，该星座+金星活跃的四分之一；
                // 不满足以上条件，
                //     若金星在火象星座，天秤座+金星活跃值的四分之一
                //     若金星在土象星座，金牛座+金星活跃值的二分之一
                //     若金星在风象星座，天秤座+金星活跃值的二分之一
                //     若金星在水象星座，金牛座+金星活跃值的四分之一
                $st = false;
                if ($st == false && $this->base_data['planets'][$i]['in_sign_id'] == 2)
                {
                    // 金星落金牛座
                    $this->signs_score[2] += $actives[$i]['total'] * 0.5;
                    $st = true;
                    continue;
                } elseif ($st == false && $this->base_data['planets'][$i]['in_sign_id'] == 7)
                {
                    // 金星落天秤座
                    $this->signs_score[7] += $actives[$i]['total'] * 0.5;
                    $st = true;
                    continue;
                }
                foreach ($characteristic as $k => $chara)
                {
                    // 存在互容接纳关系
                    if ($st == false && ($chara['status'] == 1 || $chara['status'] == 2))
                    {
                        $sign1 = $this->base_data['planets'][$chara['id1']]['in_sign_id'];
                        $sign2 = $this->base_data['planets'][$chara['id2']]['in_sign_id'];
                        if (($chara['id1'] == $i && $sign2 == 2) || ($chara['id2'] == $i && $sign1 == 2))
                        {
                            $this->signs_score[2] += $actives[$i]['total'] * 0.5;
                            $st = true;
                            continue;
                        } elseif (($chara['id1'] == $i && $sign2 == 7) || ($chara['id2'] == $i && $sign1 == 7))
                        {
                            $this->signs_score[7] += $actives[$i]['total'] * 0.5;
                            $st = true;
                            continue;
                        }
                    }
                }
                // 不满足以上两个条件，则观察升日月金火是否落在金牛座或天秤座，落的话，该星座+水星活跃的四分之一
                if ($st == false)
                {
                    if ($this->base_data['planets'][0]['in_sign_id'] == 2)
                    {
                        $this->signs_score[2] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][1]['in_sign_id'] == 2)
                    {
                        $this->signs_score[2] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][2]['in_sign_id'] == 2)
                    {
                        $this->signs_score[2] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][4]['in_sign_id'] == 2)
                    {
                        $this->signs_score[2] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][ASC]['in_sign_id'] == 2)
                    {
                        $this->signs_score[2] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][0]['in_sign_id'] == 6)
                    {
                        $this->signs_score[6] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][1]['in_sign_id'] == 6)
                    {
                        $this->signs_score[6] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][2]['in_sign_id'] == 6)
                    {
                        $this->signs_score[6] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][4]['in_sign_id'] == 6)
                    {
                        $this->signs_score[6] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                    if ($this->base_data['planets'][ASC]['in_sign_id'] == 6)
                    {
                        $this->signs_score[6] += $actives[$i]['total'] * 0.25;
                        $st = true;
                    }
                }
                if ($this->base_data['planets'][$i]['in_sign_id'] % 4 == 1)
                {
                    $this->signs_score[7] += $actives[$i]['total'] * 0.5 * 0.5;
                    $st = true;
                    continue;
                } elseif ($this->base_data['planets'][$i]['in_sign_id'] % 4 == 2)
                {
                    $this->signs_score[2] += $actives[$i]['total'] * 1 * 0.5;
                    $st = true;
                    continue;
                } elseif ($this->base_data['planets'][$i]['in_sign_id'] % 4 == 3)
                {
                    $this->signs_score[7] += $actives[$i]['total'] * 1 * 0.5;
                    $st = true;
                    continue;
                } elseif ($this->base_data['planets'][$i]['in_sign_id'] % 4 == 4)
                {
                    $this->signs_score[2] += $actives[$i]['total'] * 0.5 * 0.5;
                    $st = true;
                    continue;
                }
            }
            //若火星在
            // 	火象星座，白羊座+火值
            // 	土象星座，天蝎座+火值的三分之一
            // 	风象星座，白羊座+火值的二分之一
            // 	水象星座，天蝎座+火值的二分之一
            // 白羊座+火星活跃值
            elseif ($i == 4)
            {
//                if($this->base_data['planets'][$i]['in_sign_id'] % 4 == 1)
//                    $this->signs_score[1] += $actives[$i]['total'] * 1;
//                elseif($this->base_data['planets'][$i]['in_sign_id'] % 4 == 2)
//                    $this->signs_score[8] += $actives[$i]['total'] / 3;
//                elseif($this->base_data['planets'][$i]['in_sign_id'] % 4 == 3)
//                    $this->signs_score[1] += $actives[$i]['total'] * 0.5;
//                elseif($this->base_data['planets'][$i]['in_sign_id'] % 4 == 4)
//                    $this->signs_score[8] += $actives[$i]['total'] * 0.5;
                $this->signs_score[1] += $actives[$i]['total'] * 1 * 0.5;
            }
            //若木星在
            // 	火象星座，射手座+木值
            // 	土象星座，双鱼座+木值的三分之一
            // 	风象星座，射手座+木值的二分之一
            // 	水象星座，双鱼座+木值的二分之一
            // 射手座+木星活跃值
            elseif ($i == 5)
            {
//                if($this->base_data['planets'][$i]['in_sign_id'] % 4 == 1)
//                    $this->signs_score[9] += $actives[$i]['total'] * 1;
//                elseif($this->base_data['planets'][$i]['in_sign_id'] % 4 == 2)
//                    $this->signs_score[12] += $actives[$i]['total'] / 3;
//                elseif($this->base_data['planets'][$i]['in_sign_id'] % 4 == 3)
//                    $this->signs_score[9] += $actives[$i]['total'] * 0.5;
//                elseif($this->base_data['planets'][$i]['in_sign_id'] % 4 == 4)
//                    $this->signs_score[12] += $actives[$i]['total'] * 0.5;
                $this->signs_score[9] += $actives[$i]['total'] * 1 * 0.5;
            }
            //若土星在
            // 	火象星座，水瓶座+土值的三分之一
            // 	土象星座，摩羯座+土值
            // 	风象星座，水瓶座+土值的二分之一
            // 	水象星座，摩羯座+土值的二分之一
            // 摩羯座+土星活跃值
            elseif ($i == 6)
            {
//                if($this->base_data['planets'][$i]['in_sign_id'] % 4 == 1)
//                    $this->signs_score[11] += $actives[$i]['total'] / 3;
//                elseif($this->base_data['planets'][$i]['in_sign_id'] % 4 == 2)
//                    $this->signs_score[10] += $actives[$i]['total'] * 1;
//                elseif($this->base_data['planets'][$i]['in_sign_id'] % 4 == 3)
//                    $this->signs_score[11] += $actives[$i]['total'] * 0.5;
//                elseif($this->base_data['planets'][$i]['in_sign_id'] % 4 == 4)
//                    $this->signs_score[10] += $actives[$i]['total'] * 0.5;
                $this->signs_score[10] += $actives[$i]['total'] * 1 * 0.5;
            } // 水瓶座+天王星活跃值
            elseif ($i == 7)
            {
                $this->signs_score[11] += $actives[$i]['total'] * 1 * 0.5;
            } // 双鱼座+海王星活跃值
            elseif ($i == 8)
            {
                $this->signs_score[12] += $actives[$i]['total'] * 1 * 0.5;
            } // 天蝎座+冥王星活跃值
            elseif ($i == 9)
            {
                $this->signs_score[8] += $actives[$i]['total'] * 1 * 0.5;
            }

        }
    }

}
